import Vue from 'vue'
import VueRouter from 'vue-router'
import Film from '@/views/Film'
import Nowplaying from '@/views/film/Nowplaying'
import Comingsoon from '@/views/film/Comingsoon'
import Cinema from '@/views/Cinema'
import Center from '@/views/Center'
import Detail from '@/views/Detail'
import Login from '@/views/Login'

Vue.use(VueRouter)

/* const auth = {
  isLogin() {
    return true
  }
} */

const routes = [
  {
    path: '/film',
    component: Film,
    children: [
      {
        path: 'nowplaying',
        component: Nowplaying
      },
      {
        path: 'comingsoon',
        component: Comingsoon
      },
      {
        path: '',
        redirect: 'nowplaying'
      }
    ]
  },
  {
    path: '/cinema',
    component: Cinema
  },
  {
    path: '/center',
    alias: '/my',
    component: Center
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/detail/:id', // 动态路由
    name: 'moviedetail',
    component: Detail,
    props: true
  },
  {
    path: '*',
    redirect: '/film'
  }
]

const router = new VueRouter({
  // mode: 'history',
  // base: process.env.BASE_URL,
  routes
})
// 全局守卫
/* router.beforeEach((to, from, next) => {
  // console.log(to)
  if (to.path === '/center') {
    console.log('盘查...')

    if (auth.isLogin()) {
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
}) */

export default router
